【问题处理】ORA | 您所在的位置:网站首页 › ora01722无效数字怎么解决 查询 › 【问题处理】ORA |
SQL> create table tmao (id varchar2(64)) 2 SQL> create table tmao (id varchar2(64)); Table created SQL> insert into tmao values(818); 1 row inserted SQL> insert into tmao values('819'); 1 row inserted SQL> commit; Commit complete SQL> select * from tmao where id=818; ID ---------------------------------------------------------------- 818 SQL> select * from tmao where id=819; ID ---------------------------------------------------------------- 819 SQL> insert into tmao values('4r'); 1 row inserted SQL> commit; Commit complete SQL> select * from tmao where id=819; select * from tmao where id=819 ORA-01722: invalid number SQL> create index inf on tmao(to_number(id)); create index inf on tmao(to_number(id)) ORA-01722: invalid number 最开始发起这个事情的原因,是开发人员问我,为啥在生产上执行id=819,不需要加引号就可以查不出来结果,而测试环境就需要加引号才可以查出来,如果不加引号就报错,无效的数字。其实做完实验,会发现很简单,原因就是id这是varchar2类型的,当我们不加引号的时候,走的是全表扫描,所以当扫描到不是纯数字的行时就会报错。
|
CopyRight 2018-2019 实验室设备网 版权所有 |